/* Copyright 2008 Robert C. Brinson <rbrinson@gmail.com>
 * 
 * This file is part of PictureTagger.
 *
 * PictureTagger is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * PictureTagger is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PictureTagger.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;

namespace PictureTagger.PictureCollection
{
	
	
	public class Picture
	{
		private bool _dirty;
		private bool _dirtyHeadline;
		private bool _dirtyCaption;
		private bool _dirtyKeywords;
		private string _fullName;
		private string _headline;
		private string _prevHeadline;
		private string _caption;
		private string _prevCaption;
		private List<string> _keywords;
		private List<string> _prevKeywords;
		private byte[] _thumbNail;
		
		public Picture(string fullName, string headline, string caption, List<string> keywords, byte[] thumbNail)
		{
			_dirty = false;
			_dirtyHeadline = false;
			_dirtyCaption = false;
			_dirtyKeywords = false;
			_fullName = fullName;
			_headline = headline;
			_prevHeadline = headline;
			_caption = caption;
			_prevCaption = caption;
			_keywords = keywords;
			_prevKeywords = keywords;
			_thumbNail = thumbNail;
		}
		
		public bool IsDirty
		{
			get { return _dirty; }
		}
		
		internal bool Dirty
		{
			set { _dirty = value; }
		}
		
		public bool IsHeadlineDirty
		{
			get { return _dirtyHeadline; }
		}
		
		public bool IsCaptionDirty
		{
			get	{ return _dirtyCaption; }
		}
		
		public bool IsKeywordsDirty
		{
			get { return _dirtyKeywords; }
		}
		
		public string FullName
		{
			get { return _fullName; }
		}
		
		public string Headline
		{
			get { return _headline; }
			
			set
			{
				_dirty = true;
				if (!_dirtyHeadline)
				{
					_dirtyHeadline = true;
					_prevHeadline = _headline;
				}
				_headline = value;
			}
		}
		
		public string Caption
		{
			get { return _caption; }
			
			set
			{
				_dirty = true;
				if (!_dirtyCaption)
				{
					_dirtyCaption = true;
					_prevCaption = _caption;
				}
				_caption = value;
			}
		}
		
		public List<string> Keywords
		{
			get { return _keywords; }
			
			set
			{
				_dirty = true;
				if (!_dirtyKeywords)
				{
					_dirtyKeywords = true;
					_prevKeywords = _keywords;
				}
				_keywords = value;
			}
		}
		
		public byte[] ThumbNail
		{
			get { return _thumbNail; }
		}
		
		internal void Reset()
		{
			if (_dirtyHeadline)
			{
				_headline = _prevHeadline;
			}
			if (_dirtyCaption)
			{
				_caption = _prevCaption;
			}
			if (_dirtyKeywords)
			{
				_keywords = _prevKeywords;
			}
			
			CleanDirtyFlags();
		}
		
		internal void ResetHeadline()
		{
			if (_dirtyHeadline)
			{
				_headline = _prevHeadline;
			}
			_dirtyHeadline = false;
			ReevaluateDirty();
		}
		
		internal void ResetCaption()
		{
			if (_dirtyCaption)
			{
				_caption = _prevCaption;
			}
			_dirtyCaption = false;
			ReevaluateDirty();
		}
		
		internal void ResetKeywords()
		{
			if (_dirtyKeywords)
			{
				_keywords = _prevKeywords;
			}
			_dirtyKeywords = false;
			ReevaluateDirty();
		}
		
		internal void CleanDirtyFlags()
		{
			_dirtyHeadline = false;
			_dirtyCaption = false;
			_dirtyKeywords = false;
			_dirty = false;
		}
		
		private void ReevaluateDirty()
		{
			if (!_dirtyHeadline && !_dirtyCaption && !_dirtyKeywords)
			{
				_dirty = false;
			}
		}
	}
}